/**
 * 包含了续班报表中用的的函数
 */

// 判断list1 是否包含 list2
function containArray(list1, list2) {
    if (list1.length < list2.length) {
        return false;
    }
    for (let i = 0; i < list2.length; i++) {
        if (list2[i] !== list1[i]) {
            return false;
        }
    }

    return true;
}

export function removeList(list1, list2) {
    const result = [];
    for (const l of list1) {
        if (!containArray(l, list2)) {
            result.push(l);
        }
    }

    return result;
}

// 二维数组转化 obj[]
export function processReduce(list, columns) {
    const map1 = new Map();
    for (const ele of columns) {
        map1.set(ele.text, ele.dId);
    }
    const result = [];
    for (const i of list) {
        const inner = [];
        for (const j of i) {
            inner.push({
                dimensionId: map1.get(j.split('$$')[0]),
                dimensionName: j.split('$$')[0],
                value: j.split('$$')[1],
            });
        }
        result.push(inner);
    }

    return result;
}

// 获取map的下一个key
export function getMapNextKey(map, key) {
    const keys = [...map.keys()];
    const index = keys.indexOf(key);

    if (index < keys.length - 1) {
        return keys[index + 1];
    }
    return keys[0];
}

